package com.qdsgjsfk.vision.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qdsgjsfk.vision.R;

import butterknife.BindView;
import butterknife.OnClick;

import com.qdsgjsfk.vision.base.BaseActivity;
import com.qdsgjsfk.vision.ui.fragment.TaskListFragment;

import java.util.Objects;

/**
 * @time 2020/9/24 17:26
 */

public class TaskListActivity extends BaseActivity {


    @BindView(R.id.timeline_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.timeline_viewpager)
    ViewPager mViewPager;
    long classId;
    @BindView(R.id.title)
    RelativeLayout title;
    @BindView(R.id.tv_title)
    TextView tv_title;

    @OnClick(R.id.btn_search)
    void btn_search() {
        startActivityForResult( SearchActivity.class, 1 );
    }

    @Override
    protected void initViews() {
        mViewPager.setAdapter( new StudentListAdapter( this, getSupportFragmentManager() ) );
        mTabLayout.setupWithViewPager( mViewPager );
        mTabLayout.setTabMode( TabLayout.MODE_FIXED );
        mTabLayout.setTabGravity( TabLayout.GRAVITY_FILL );

        mViewPager.setCurrentItem( 0 );
        Objects.requireNonNull( mTabLayout.getTabAt( 0 ) ).select();
        title.bringToFront();
    }

    @Override
    protected void initData() {
        tv_title.setText( getIntent().getStringExtra( "title" ) );
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_task_list;
    }


    static class StudentListAdapter extends FragmentPagerAdapter {
        private static final int PAGE_COUNT = 5;

        StudentListAdapter(Context context, FragmentManager fm) {
            super( fm );
        }

        @Override
        public Fragment getItem(int position) {
            int planType;// 0-全部 101-普查计划 102-抽查计划 104-自查计划  103-复查计划
            switch (position) {
                case 0:
                    planType = 0;
                    break;
                case 1:
                    planType = 101;
                    break;
                case 2:
                    planType = 102;
                    break;
                case 3:
                    planType = 104;
                    break;
                case 4:
                    planType = 103;
                    break;
                default:
                    planType = 0;
                    break;
            }
            return TaskListFragment.newInstance( planType );
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "全部";
                case 1:
                    return "普查";
                case 2:
                    return "抽查";
                case 3:
                    return "自查";
                case 4:
                    return "复查";
                default:
                    return "";
            }
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult( requestCode, resultCode, data );
        if (resultCode == Activity.RESULT_OK) {
            setResult( Activity.RESULT_OK, data );
            finish();
        }
    }
}
